import store from '@/store/index'

export const colorGrey = '#909399'
export const colorBlue = '#409EFF'
export const colorRed = '#F56C6C'
export const colorOrange = '#E6A23C'
export const colorGreen = '#67C23A'
export const widthxs = '80px'
export const widthsm = '100px'
export const widthdf = '120px'
export const widthlg = '130px'
export const widthxl = '140px'
export const widthxxl = '160px'
export const widthxsl = '180px'
export const widthssl = '210px'

// -4 已作废 -3 报价拒绝 -2 订单拒绝 -1 待审批 0 待报价 1 已报价
// 2 待出库 3 已出库 4 已配送 5 已报装

// -1: "订单审批",
//  0: "制作报价",
//  1: "审批报价",
//  2: "开始出库",
//  3: "完成配送",
//  4: "我要报装",
//  5: "外部访客",
//  100: "门店下单",
//  101: "入库",
//  102: "补单",
//  103: "指定出库业务员",
//  104: "出入库记录",
//  105: "利润、成本",
//  199: "后台系统登录"
//  198: "后台套件管理"
//  197: "后台产品管理"
//  196: "后台订单管理"
//  195: "后台订单-制作报价"
//  194: "后台订单-出库时间"
//  193: "后台订单-导出Excel"
//  192: "后台库存-导入库存"
//  191: "后台库存明细-售价/成本字段"
//  190: "后台-库存管理一级菜单"
//  189: "后台-团队管理一级菜单"
//  188: "后台-财务管理一级菜单"
//  187: "后台-财务管理0:待处理"
//  186: "后台-财务管理1:已付款"
//  185: "后台-财务管理2:已驳回"
//  184: "后台-财务管理付款按钮"
//  183: "后台-财务管理驳回按钮"
//  182: "后台-财务待处理删除按钮"
//  181: "后台-财务已付款删除按钮"
//  180: "后台-财务已驳回删除按钮"
//  179: "后台-售后列表删除按钮"
//  178: "后台-财务管理-个人驳回列表"
//  177: "后台-订单管理-成本导出按钮"
//  176 品牌方台账菜单
//  175 仓库方台账菜单

// 录入订单按钮 200
// CAD图纸上传 201
// 杂项录入按钮 202
// 回款录入按钮 203
// 发给仓库按钮 204
// 回款详情按钮 205
// 杂项详情按钮 206
// 订单编辑按钮 207
// 订单删除按钮 208
// 仓库订单删除按钮 209
// 订单管理菜单 299
// 仓库订单列表菜单 298
// 售后列表菜单 297
// 售后新增按钮 296
// 售后确认完成按钮 295
// 应收金额 294
// 已回款总额 293
//仓储区报货单 211
// 营业区报货单 210
//出库按钮 212
//工厂库存 301
//采购单列表 302
//确认订单 303
//回滚库存 304
//超管品牌方审核按钮 999
//品牌方台账-报价单运费（跟单加财务） 998
//下载合同 （跟单+admin）997

//仓库报损 307
//仓库入库 308
//工厂确认报损 309
//工厂出库 310

// -4 已作废 -3 报价拒绝 -2 订单拒绝 -1 待审批 0 待报价 1 已报价
// 2 待出库 3 已出库 4 已配送 5 已报装

export const QUOTE_STATUS = [-3, 1, 2, 3, 4, 5]

export const statusRenderMap = (map) => {
    const status = {}
    const tag = {}
    for (const key in map) {
        if (Object.hasOwnProperty.call(map, key)) {
            const value = map[key]
            status[key] = value[0]
            tag[key] = value[1]
        }
    }
    return statusRender(status, tag)
}
export const ORDER_STATUS = {
    '-1': '待审批',
    '-2': '订单拒绝',
    '-3': '报价拒绝',
    '-4': '已作废',
    0: '待报价',
    1: '已报价',
    2: '待出库',
    3: '已出库',
    4: '已配送',
    5: '已报装',
}

export const ORDER_STATUS_BTN = {
    '-1': '订单审批',
    // 0: "制作报价",
    1: '审批报价',
    // 2: "开始出库",
    3: '完成配送',
}

export const ORDER_STATUS_COLOR = {
    '-1': colorBlue,
    // 0: colorGreen,
    1: colorOrange,
    // 2: colorBlue,
    3: colorGreen,
}

export const FINANCE_TYPE_STATUS = {
    afterSale: '售后单',
    install: '安装单',
}

export const FINANCE_TYPE_TAG_STATUS = {
    afterSale: 'danger',
    install: 'success',
}

export const EXTRA_ORDER_STATUS = {
    '-1': '拒绝',
    0: '待审核',
    1: '通过',
}
export const EXTRA_ORDER_TAG_STATUS = {
    '-1': 'danger',
    0: '',
    1: 'success',
}

export const ORDER_TAG_STATUS = {
    '-4': 'info',
    '-3': 'danger', // "报价拒绝"
    '-2': 'danger', // "订单拒绝"
    '-1': 'warning', // "待审批"
    0: 'warning', // "待报价"
    1: '', // "已报价"
    2: 'warning', // "待出库"
    3: 'success', // "已出库"
    4: 'success', // "已配送"
    5: '',
}

export const STATUS_TAG = {
    0: 'danger',
    1: '',
}

export const AFTERSALE_TAG = {
    0: '未完成',
    1: '已完成',
}

export const EXTRA_TAG = {
    0: '物流破损',
    1: '少捡漏捡',
}

export const CLASSIFY_STATUS = {
    0: '停用',
    1: '启用',
}

export const PRODUCT_STATUS = {
    0: '下架',
    1: '上架',
}

export const INOUT_STATUS = {
    0: '出库',
    1: '入库',
}

export const INOUT_TAG_STATUS = {
    0: 'success',
    1: '',
}

export const AREA_MAP = {
    // 43: '宁乡壹',
    // 46: '宁乡贰',
    // 44: '广东',
    // 45: '广西',
    // 52: '贵州',
    // 53: '云南',
    // 54: '武汉',
    // 55: '西安1',
    // 56: '西安2',
    // 11: "北京",
    // 12: "天津",
    // 13: "河北",
    // 14: "山西",
    // 15: "内蒙古",
    // 21: "辽宁",
    // 22: "吉林",
    // 23: "黑龙江",
    // 31: "上海",
    // 32: "江苏",
    // 33: "浙江",
    // 34: "安徽",
    // 35: "福建",
    // 36: "江西",
    // 37: "山东",
    // 41: "河南",
    // 42: "湖北",
    // 46: "海南",
    // 50: "重庆",
    // 51: "四川",
    // 52: "贵州",
    // 53: "云南",
    // 54: "西藏",
    // 61: "陕西",
    // 62: "甘肃",
    // 63: "青海",
    // 64: "宁夏",
    // 65: "新疆",
    // 81: "香港",
    // 82: "澳门",
}

export const createdColumn = {
    label: '创建时间',
    prop: 'createdTime',
    minWidth: '82px',
}

export const updatedColumn = {
    label: '修改时间',
    prop: 'updatedTime',
    minWidth: widthxsl,
}

export const sortIndex = {
    label: '序号',
    prop: 'sortIndex',
    minWidth: '50px',
    render: function (h, scope) {
        const {column, row, $index, pageSize = 10, currentPage = 1} = scope
        return h('span', {}, (currentPage - 1) * pageSize + $index + 1)
    },
}

export const inventoryColumn = {
    label: '库存',
    prop: 'count',
    minWidth: widthsm,
    render: function (h, scope) {
        const {column, row} = scope
        return h(
            'span',
            {
                style: {
                    fontSize: '20px',
                    fontWeight: 'bolder',
                },
            },
            row[column.property]
        )
    },
}

export const _h = function (
    fn,
    color = colorGrey,
    evt = 'edit',
    text = '修改',
    params = {}
) {
    return fn(
        'span',
        {
            style: {
                color,
                marginRight: '8px',
                cursor: 'pointer',
            },
            on: {
                click: () => {
                    // console.log('下划线—hhhhh', evt, params)
                    this.$emit('handleRender', evt, params || {})
                },
            },
        },
        text
    )
}

export const _tag = function (fn, text = '开启', type = '', tag = 'el-tag') {
    if (!text) return null
    return fn(
        tag,
        {
            props: {
                type,
            },
        },
        text
    )
}

export const render = function (h, scope) {
    const {column, row} = scope
    return h(
        'span',
        {
            style: {
                color: colorBlue,
                cursor: 'pointer',
            },
            on: {
                click: () => {
                    this.$emit('handleRender', column.property)
                },
            },
        },
        row[column.property]
    )
}

export const statusRender = (
    statusMap = CLASSIFY_STATUS,
    tagMap = STATUS_TAG,
    tag = 'el-tag'
) => {
    return function (h, scope) {
        const {column, row} = scope
        const value = row[column.property]
        return _tag.call(
            this,
            h,
            statusMap[value] || value,
            tagMap[value] || '',
            tag
        )
    }
}

export const orderStatusRender = (
    statusMap = CLASSIFY_STATUS,
    tagMap = STATUS_TAG
) => {
    return function (h, scope) {
        const {column, row} = scope
        const value = row[column.property]
        return _tag.call(this, h, statusMap[value] || value, tagMap[value] || '')
    }
}

export const directoryColumn = {
    label: '套件',
    prop: 'directoryId',
    minWidth: widthxsl,
    render: function (h, scope) {
        const {column, row} = scope
        const value = row[column.property] || ''
        return h('span', {}, store.state.directoryMap[value])
    },
}

export const areaColumn = {
    label: '区域',
    prop: 'area',
    minWidth: widthsm,
    render: function (h, scope) {
        const {column, row} = scope
        const value = row[column.property]
        return h('div', this.$store.state.areaMap[value] || '--')
    },
}

export const _render = function (h, scope) {
    const {column, row} = scope
    return h('span', {}, row[column.property] || '-')
}
export const goodsFeeColumn = {
    label: '货物运费',
    prop: 'goodsFee',
    minWidth: widthdf,
    render: _render,
}
export const installFeeColumn = {
    label: '安装费用',
    prop: 'installFee',
    minWidth: widthdf,
    render: _render,
}
export const hotelFeeColumn = {
    label: '安装住宿费用',
    prop: 'hotelFee',
    minWidth: widthdf,
    render: _render,
}
export const trafficFeeColumn = {
    label: '交通费用',
    prop: 'trafficFee',
    minWidth: widthdf,
    render: _render,
}
export const otherFeeColumn = {
    label: '其他费用',
    prop: 'otherFee',
    minWidth: widthdf,
    render: _render,
}

export const PRODUCT_SORT = [
    'HK',
    'HZ',
    'H4-K-2',
    'H5-K-2',
    'H4-K-4',
    'H5-K-4',
    'H5-K-3',
    'H4-K-3',
    'H5-Z-1',
    'H4-Z-1',
    'H5-K-1',
    'H4-K-1',
    'H5-K-5',
    'H4-K-5',
    'CXT-1',
    'CXT-2',
    'HZB',
    'H-K-2-黄',
    'H1-K-2-黄',
    'H-K-4',
    'H1-K-4',
    'H2-K-4',
    'H1-Z-2',
    'H2-Z-2',
    'H-K-2',
    'H1-K-2',
    'H2-K-2',
    'HKT',
    'H1-Z-3',
    'H2-Z-3',
    'HZT',
    'H-K-3',
    'H1-K-3',
    'H2-K-3',
    'H1-Z-1',
    'H2-Z-1',
    'H-K-1',
    'H1-K-1',
    'H2-K-1',
    'H1-Z-4',
    'H2-Z-4',
    'H-KF-1',
    'H1-KF-2',
    'H2-KF-3',
    'HG',
    'HGD',
    'H-K-5',
    'H1-K-5',
    'H2-K-5',
    'TS-1',
    'H-K-6',
    'H1-K-6',
    'H2-K-6',
    'LJT',
    'DZ',
    'NNDZ',
    'DP-4',
    'DP-3',
    'DP-2',
    'DP-1',
    'S-Z-单',
    'S-Z-双',
    'SZB-左',
    'SZB-右',
    'SZB-中',
    'S-K-左',
    'S-K-右',
    'S-K-中',
    'S-K-13',
    'S2-K-10',
    'S-K-1',
    'S-K-2',
    'S-K-3',
    'S-K-4',
    'S-K-5',
    'S-Z-2',
    'S-K-6',
    'S2-K-1',
    'S2-K-2',
    'S2-K-3',
    'S2-K-4',
    'S2-Z-1',
    'S2-K-5',
    'S2-K-6',
    'S-K-9',
    'S2-K-9',
    'S-K-10',
    'SZ-4',
    'S-K-12',
    'ZJ',
    'SZ-3',
    'S-K-11',
    'S-K-12',
    'S-K-8',
    'S2-K-8',
    'DK-1',
    'DK-2',
    'XK-1',
    'XK-2',
    'HZ-DP',
    'S-K-14',
    'S2-K-13',
    'M8-50',
    'M8',
    'M8-20',
    'M4-16',
    'TS-2',
    'GL',
    'S-DT-1',
    'S2-DT-2',
    'DT-1',
    'DT-2',
    'DT-3',
    'DT-4',
    'DT-5',
    'DT-6',
    'SYD',
    'ZYTC',
    'XXTC',
    'SCTC',
    'PBTC',
    'CKDB',
    'QCJ-1',
    'QCJ-1.5',
    'QCJ-2',
    'QCJ-4',
    'QCJ-6',
    'QCJ-3',
    'QCJ-5',
    'QCJ-7',
    'ZCJ-1',
    'ZCJ-2',
    'ZCJ-4',
    'ZCJ-5',
    'ZCJ-3',
]
